package com.talkyun.ocean.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class StreamReader {

    public static List<String> readLines(InputStream ins) {
        try {
            return doReadLines(ins);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                ins.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }

    private static List<String> doReadLines(InputStream ins) throws IOException {
        if (ins == null) {
            return Collections.emptyList();
        }
        List<String> list = new ArrayList<String>();
        BufferedReader br = new BufferedReader(new InputStreamReader(ins));
        for (String line = br.readLine(); line != null; line = br.readLine()) {
            if (line.trim().length() == 0) {
                continue;
            }
            list.add(line.trim());
        }
        return list;
    }
}